#include "demuxerthread.h"

DemuxerThread::DemuxerThread(QObject *parent) : QThread(parent)
{

    connect(this,&QThread::finished,this,&QThread::deleteLater);
}

DemuxerThread::~DemuxerThread()
{

    if(_demuxer != nullptr) {

        delete  _demuxer;
        _demuxer = nullptr;
    }

    disconnect();

    requestInterruption();

    wait();

    quit();

    qDebug() << "DemuxerThread destory";

}

void DemuxerThread::run()
{
#if 0
    const char* videoPath = "/Users/tgy/Documents/ffmpeg/video/demo02.mp4";

    YUVFileSpec yuvFileSpec(0,0,0,AV_PIX_FMT_NONE,"/Users/tgy/Documents/ffmpeg/video/demo02_strip_02.yuv");
    PCMFileSpec pcmFileSpec(0,0,AV_SAMPLE_FMT_NONE,"/Users/tgy/Documents/ffmpeg/video/demo02_strip_02.pcm");
#else
    // /Users/apple/Documents/ffmpeg/qt/video
    const char* videoPath = "/Users/apple/Documents/ffmpeg/qt/video/demo02.MP4";

    YUVFileSpec yuvFileSpec(0,0,0,AV_PIX_FMT_NONE,"/Users/apple/Documents/ffmpeg/qt/video/demo02_strip_02.yuv");
    PCMFileSpec pcmFileSpec(0,0,AV_SAMPLE_FMT_NONE,"/Users/apple/Documents/ffmpeg/qt/video/demo02_strip_02.pcm");
#endif


    _demuxer = new Demuxer();
    _demuxer->demuxer(videoPath,yuvFileSpec,pcmFileSpec);

    av_get_pix_fmt_name(yuvFileSpec.getFormat());
    qDebug() << "YUV spec format:"<< av_get_pix_fmt_name(yuvFileSpec.getFormat())
             << "width:" << yuvFileSpec.getWidth()
             <<"height:" << yuvFileSpec.getHeight()
             << "fps" << yuvFileSpec.getFPS();



    qDebug() << "PCM spec: format" << av_get_sample_fmt_name(pcmFileSpec.getSampleFormat())
             << "num channels:" << pcmFileSpec.getNumChannel()
             << "sample rate" << pcmFileSpec.getSampleRate();

}


